package cn.yunhe.biz.impl;

import cn.yunhe.biz.HouseBiz;
import cn.yunhe.dao.HouseDao;
import cn.yunhe.dao.impl.HouseDaoImpl;
import cn.yunhe.model.House;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Transactional(propagation = Propagation.SUPPORTS,readOnly = true,rollbackFor = RuntimeException.class)
public class HouseBizImpl implements HouseBiz {
    HouseDao houseDao

    @Transactional(propagation = Propagation.REQUIRED,readOnly = false)
    @Override
    public boolean insertHouse(House house) {
        return houseDao.insertHouse(house);
    }

    @Transactional(propagation = Propagation.REQUIRED,readOnly = false)
    @Override
    public boolean updateHouse(House house) {
        return houseDao.updateHouse(house);
    }

    @Transactional(propagation = Propagation.REQUIRED,readOnly = false)
    @Override
    public boolean deleteHouse(int hid) {
        return houseDao.deleteHouse(hid);
    }

    @Override
    public House getHouseById(int hid) {
        return houseDao.getHouseById(hid);
    }

    @Override
    public List<House> searchHouse(House house) {
        return houseDao.searchHouse(house);
    }

    @Override
    public List<House> searchHouse(String hql) {
        return houseDao.searchHouse(hql);
    }


    @Transactional(propagation = Propagation.REQUIRED,readOnly = false)
    @Override
    public boolean insertHouseList(List<House> houseList) {
        try{
            for (House house:houseList){
                houseDao.insertHouse(house);
            }
            return true;
        }catch (Exception e){
            throw new RuntimeException();
        }
    }

    public HouseDao getHouseDao() {
        return houseDao;
    }

    public void setHouseDao(HouseDao houseDao) {
        this.houseDao = houseDao;
    }

}
